<template>
  <view class="popup">
    <image
      mode="aspectFill"
      class="goodsImage_pop"
      :src="specGoodsData.goodsImg"
    ></image>
    <!-- 头部商品开始 -->
    <view class="topGoods">
      <view class="goodsInfo">
        <view class="goodsName moreText">{{ specGoodsData.name }}</view>
        <view class="goodsDescription">{{
          specGoodsData.goodsDescription
        }}</view>
        <br />
        <view class="goodsDescription">{{
          specGoodsData.goodsDescription
        }}</view>

        <!-- 占位符 -->
        <view class="null_box"></view>
      </view>
    </view>
    <!-- 头部商品结束 -->
    <!-- 商品规格开始 -->
    <view class="popupCenter">
      <scroll-view
        scroll-with-animation="true"
        enable-back-to-top="true"
        scroll-y="true"
        style="max-height: 520rpx; padding-bottom: 24rpx"
      >
        <!-- 属性 -->
        <view
          class="goodsSpec"
          v-if="specGoodsData.attr_array && specGoodsData.attr_array.length > 0"
        >
          <view class="name">温度</view>
          <view class="specList">
            <button
              @click="onfreeSpecs(item, index)"
              v-for="(item, index) in specGoodsData.attr_array"
              :key="index"
              size="mini"
              type="default"
              class="button"
              :class="{ click: current == index }"
              :style="[
                current == index
                  ? {
                      background: freeSpecsButtonBackground,
                      color: PrimaryColor,
                      border: `1px solid transparent`,
                    }
                  : {},
              ]"
            >
              {{ item }}
            </button>
          </view>
        </view>

        <!-- 占位符 -->
        <view class="null_box"></view>

        <!-- 备注 -->
        <view class="remark">
          <text class="remark_title">備注</text>
          <u--input
            customStyle="background-color: rgba(240, 240, 240, 1);"
            placeholderStyle="color: rgba(75, 75, 75, 0.56)"
            placeholder="请输入内容"
            border="surround"
          ></u--input>
        </view>

        <!-- 占位符 -->
        <view class="null_box"></view>

        <view
          style="
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-top: 30rpx;
          "
        >
          <view style="display: flex; align-items: center"
            ><view class="retailPrice_new"> $ 300 </view>

            <view class="memberPrice">
              <view class="VIP">
                <img :src="'./static/demo/VIP.png'" alt="" />
              </view>
              <view class="money">$299.99</view>
            </view></view
          >

          <view class="numberBox u-flex">
            <view
              class="minus u-flex"
              style="line-height: 54rpx"
              @click="minus"
            >
              -
            </view>
            <view class="inputBox u-flex">
              <input
                v-model="num"
                @input="inputChange"
                class="u-flex"
                type="number"
              />
            </view>
            <view class="plus u-flex" style="line-height: 54rpx" @click="plus">
              +
            </view>
          </view>
        </view>

        <!-- 保存按钮 -->
        <view class="sava_btn" @click="onDetermine(specGoodsData)"
          >加入購物袋
        </view>

        <!-- 数量 -->
        <!-- <view class="u-flex" v-if="isShowNum"> -->

        <!-- <view class="numberBox u-flex">
            <view
              class="minus u-flex"
              style="line-height: 54rpx"
              @click="minus"
            >
              -
            </view>
            <view class="inputBox u-flex">
              <input
                v-model="num"
                @input="inputChange"
                class="u-flex"
                type="number"
              />
            </view>
            <view class="plus u-flex" style="line-height: 54rpx" @click="plus">
              +
            </view>
          </view> -->
        <!-- <view style="width: 220rpx;">
                              <u-number-box v-model="num" :min="1" :max="specGoodsData.totalStockCount" @plus="plus" @minus="minus"></u-number-box>
                          </view> -->
        <!-- </view> -->
      </scroll-view>
    </view>
    <!-- 商品规格结束 -->
    <!-- 确定按钮 -->
    <!-- <view class="determine" v-if="popupType == 2">
      <button
        @click="onPurchase(specGoodsData)"
        size="default"
        type="primary"
        class="button"
        :style="{ background: PrimaryColor }"
      >
        {{ buyName }}
      </button>
    </view> -->
    <!-- <view class="determine u-flex" v-else-if="popupType == 3">
      <button
        @click="onDetermine(specGoodsData)"
        size="default"
        type="primary"
        class="button u-flex-m"
        style="background: #ffa63a; margin: 0 10rpx"
      >
        加入购物车
      </button>
      <button
        @click="onPurchase(specGoodsData)"
        size="default"
        type="primary"
        class="button u-flex-m"
        style="margin: 0 10rpx"
        :style="{ background: PrimaryColor }"
      >
        {{ buyName }}
      </button> -->
    <!-- </view> -->
    <!-- <view class="determine" v-else>
      <button
        @click="onDetermine(specGoodsData)"
        size="default"
        type="primary"
        class="button" 
      >
        加入购物车
      </button>
    </view> -->
  </view>
</template>

<script>
import { mapState, mapMutations } from "vuex";
export default {
  props: {
    isPopup: {
      type: Boolean,
    },
    specGoodsData: {
      type: Object,
      default() {
        return {};
      },
    },
    //规格状态 1：默认 加入购物车 2：不加人购物车 按钮名称改成去购买 配合isAuto=true使用 3:显示加入购物车按钮、去购买按钮
    popupType: {
      type: [Number, String],
      default() {
        return 1;
      },
    },
    //是否显示数量控件 false：隐藏 true：显示
    isShowNum: {
      type: Boolean,
      default() {
        return true;
      },
    },
  },
  computed: {
    // ...mapState(["PrimaryColor"]),
  },
  data() {
    return {
      freeSpecsButtonBackground: "rgba(247, 154, 77, 1)",
      showPopup: false,
      addNumber: 1,
      disabled: true, //是否禁止规格数量控件 true：禁止
      buyName: "去购买",
      current: 0, //选择的规格
      selArray: "", //已选规格属性
      num: 1,
      PrimaryColor: "rgba(255, 255, 255, 1)",
    };
  },
  watch: {
    isPopup(val) {
      console.log(val);
      if (val) {
        setTimeout(() => {
          if (this.specGoodsData.attr_array) {
            this.selArray = this.specGoodsData.attr_array[0];
          }
        }, 100);
      }
    },
  },
  created() {},
  methods: {
    //选择属性/规格
    onfreeSpecs(e, index) {
      this.current = index;
      this.selArray = e;
      var item = {
        type: 1, //1:选择规格 2：加入购物车 3：去购买 4:输入的数量
        selArray: e,
      };
      this.$emit("change", item);
    },
    // 加入购物车
    onDetermine(e) {
      var item = {
        type: 2, //1:选择规格 2：加入购物车 3：去购买 4:输入的数量
        goods: e,
        num: this.num,
        selArray:
          this.selArray ||
          (this.specGoodsData.attr_array && this.specGoodsData.attr_array[0]),
      };
      this.$emit("change", item);
    },
    //去购买
    onPurchase(e) {
      var item = {
        type: 3, //1:选择规格 2：加入购物车 3：去购买 4:输入的数量
        goods: e,
        num: this.num,
        selArray:
          this.selArray ||
          (this.specGoodsData.attr_array && this.specGoodsData.attr_array[0]),
      };
      this.$emit("change", item);
    },
    minus() {
      if (this.num <= 1) {
        this.num = 1;
      } else {
        this.num--;
      }
      var item = {
        type: 4, //1:选择规格 2：加入购物车 3：去购买 4:输入的数量
        num: this.num,
      };
      this.$emit("change", item);
    },
    plus() {
      var maxNum = this.specGoodsData.totalStockCount || null;
      if (maxNum && this.num >= maxNum) {
        this.num = maxNum;
      } else {
        this.num++;
      }
      var item = {
        type: 4, //1:选择规格 2：加入购物车 3：去购买 4:输入的数量
        num: this.num,
      };
      this.$emit("change", item);
    },
    inputChange(event) {
      var val = event.detail.value;
      var maxNum = this.specGoodsData.totalStockCount || null;
      setTimeout(() => {
        if (val > 1) {
        } else {
          this.num = 1;
        }
        if (maxNum && val >= maxNum) {
          this.num = maxNum;
        }
      }, 1);
    },
  },
};
</script>

<style lang="scss">
.u-flex {
  /* #ifndef APP-NVUE */
  display: flex;
  /* #endif */
}
.u-flex-m {
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  flex: 1;
  overflow: hidden;
}
.moreText {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}
.popup {
  background: #fff;
  border-radius: 36.628rpx;
}
/* 头部商品开始 */
.topGoods {
  overflow: hidden;
  position: relative;
  /* #ifndef APP-NVUE */
  display: flex;
  /* #endif */
  /* border-bottom: 1px solid #f5f5f5; */
  padding: 17.442rpx 24.419rpx 17.442rpx 24.419rpx;
  box-sizing: border-box;
  .goodsInfo {
    width: 100%;
    .goodsName {
      font-size: 34.884rpx;
      font-weight: 400;
      padding-right: 35rpx;

      font-family: "Microsoft JhengHei UI";
      color: rgba(0, 0, 0, 1);
    }
    .goodsDescription {
      color: rgba(75, 75, 75, 1);
      font-size: 27.907rpx;
      font-family: "Microsoft JhengHei UI";
      margin-top: 13.953rpx;
      display: inline-block;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .goodsData {
      /* #ifndef APP-NVUE */
      display: flex;
      /* #endif */
      flex-direction: row;
      // margin-top: 4rpx;
      text {
        color: #666;
        font-size: 24rpx;
      }
      .monthlySales {
        margin-right: 20rpx;
        .clickWord {
          max-width: 300rpx;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
      }
    }
    .bottomOperation {
      /* #ifndef APP-NVUE */
      display: flex;
      /* #endif */
      flex-direction: row;
      margin-top: 10rpx;
      align-items: center;
      .retailPrice {
        /* #ifndef APP-NVUE */
        display: flex;
        /* #endif */
        flex-direction: row;
        align-items: flex-end;
        color: #fe461d;
        margin-right: 24rpx;
        .fuhao {
          font-size: 22rpx;
        }
        .Price {
          font-size: 38rpx;
          font-weight: bold;
          line-height: 38rpx;
        }
      }
    }
  }
}

.popupCenter {
  color: #333;
  position: relative;
  width: 100%;
  padding: 0 24.419rpx 17.442rpx 24.419rpx;
  .goodsSpec {
    color: #333;
    .freeSpecs {
      color: #333;
    }
    .name {
      color: rgba(35, 35, 35, 1);
      font-size: 27.907rpx;

      font-family: "Microsoft JhengHei UI";
    }
    .specList {
      margin-top: 20rpx;
      .button {
        // padding: 0rpx 44rpx;
        width: 122.093rpx;
        color: rgba(70, 70, 70, 1);
        background: rgba(255, 255, 255, 1);
        margin-right: 30rpx;
        margin-bottom: 10rpx;

        height: 50.581rpx;
        line-height: 45.581rpx;
        border-radius: 35px;

        font-size: 24.419rpx;

        text-align: center;

        border: 0.1px solid rgba(0, 0, 0, 1);
        &.click {
          color: #65b05b;
          background: #f0f9eb;
        }
        &::after {
          border: none;
        }
      }
    }
  }
}
.determine {
  padding: 20rpx 40rpx;
  background: #fff;
  .button {
    padding: 0rpx 44rpx;
    height: 90rpx;
    line-height: 90rpx;
    border-radius: 45px;
    background: #65b05b;
    border: none;
  }
}
.numberBox {
  .minus,
  .plus {
    width: 60rpx;
    height: 54rpx;
    border: 1rpx solid #eee;
    justify-content: center;
  }
  .minus {
    border-radius: 6rpx 0 0 6rpx;
  }
  .plus {
    border-radius: 0 6rpx 6rpx 0;
  }
  .inputBox {
    width: 60rpx;
    height: 54rpx;
    border-top: 1rpx solid #eee;
    border-bottom: 1rpx solid #eee;
    input {
      width: 100%;
      height: 100%;
      border: 0;
      text-align: center;
      font-size: 26rpx;
    }
  }
}

.goodsImage_pop {
  width: 100%;
  height: 317.442rpx;
  border-radius: 36.628rpx 36.628rpx 0px 0px;
}

.popup {
  overflow: hidden;
  border-radius: 36.628rpx;
}

.null_box {
  margin-top: 10.93rpx;

  background: rgba(217, 217, 217, 0.7);
  height: 1px;
}

.remark {
  margin-top: 30.93rpx;
  margin-bottom: 30.93rpx;

  display: flex;
  justify-content: space-between;
  align-items: center;

  .remark_title {
    font-family: "Microsoft JhengHei UI";
    font-size: 27.907rpx;
    font-weight: 400;
    text-align: left;

    margin-right: 34.884rpx;
  }
}

.memberPrice {
  width: 122.093rpx;
  height: 34.884rpx;
  display: flex;
  align-items: center;

  margin-left: 20.93rpx;

  .VIP {
    color: linear-gradient(
      332.18deg,
      #d9d9d9 20.91%,
      #f8ab6b 75.45%
    ) !important;
    font-family: "Microsoft PhagsPa";
    font-size: 17.442rpx;
    font-weight: 400;

    background: rgba(69, 69, 69, 1);

    width: 33.14rpx;
    align-items: center;
    display: flex;

    height: 20.93rpx;
    justify-content: center;
  }
}

.money {
  width: 87.209rpx;
  height: 20.93rpx;
  display: flex;
  background: linear-gradient(
    352.27deg,
    #ffffff -65.41%,
    #facaa2 14.99%,
    #f7ab6b 63.1%
  );

  font-family: "Abyssinica SIL";
  font-size: 15.698rpx;
  font-weight: 400;
  color: rgba(69, 69, 69, 1);
  padding-left: 5rpx;
  align-items: center;
}

.retailPrice_new {
  color: rgba(0, 0, 0, 1);
  font-family: "Microsoft PhagsPa";
  font-size: 34.884rpx;
}

.sava_btn {
  width: 568.605rpx;
  height: 85.465rpx;
  border-radius: 34.884rpx;
  background: rgba(247, 154, 77, 1);

  font-family: "Microsoft Sans Serif";
  font-size: 41.86rpx;
  text-align: center;

  display: flex;
  justify-content: center;
  align-items: center;

  color: rgba(255, 255, 255, 1);

  margin-top: 52.326rpx;
}
</style>
